<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
	"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
  <script src="lib/JSAN.js" type="text/javascript" charset="utf-8"></script>
  <script type="text/javascript" src="../lib/URI.js"></script>
</head>

<body>
<pre><script type="text/javascript" charset="utf-8">
  JSAN.use('Test.More');
  plan({ tests: 42 });
  var base = new URI("http://a/b/c/d;p?q");
  var resolve_tests = [
    // Normal examples.
    ["g:h",     "g:h"],
    ["g",       "http://a/b/c/g"],
    ["./g",     "http://a/b/c/g"],
    ["g/",      "http://a/b/c/g/"],
    ["/g",      "http://a/g"],
    ["//g",     "http://g"],
    ["?y",      "http://a/b/c/d;p?y"],
    ["g?y",     "http://a/b/c/g?y"],
    ["#s",      "http://a/b/c/d;p?q#s"],
    ["g#s",     "http://a/b/c/g#s"],
    ["g?y#s",   "http://a/b/c/g?y#s"],
    [";x",      "http://a/b/c/;x"],
    ["g;x",     "http://a/b/c/g;x"],
    ["g;x?y#s", "http://a/b/c/g;x?y#s"],
    ["",        "http://a/b/c/d;p?q"],
    [".",       "http://a/b/c/"],
    ["./",      "http://a/b/c/"],
    ["..",      "http://a/b/"],
    ["../",     "http://a/b/"],
    ["../g",    "http://a/b/g"],
    ["../..",   "http://a/"],
    ["../../",  "http://a/"],
    ["../../g", "http://a/g"],

    // Abnormal examples.
    // 1. Going up further than is possible.
    ["../../../g",    "http://a/g"],
    ["../../../../g", "http://a/g"],

    // 2. Not matching dot boundaries correctly.
    ["/./g",  "http://a/g"],
    ["/../g", "http://a/g"],
    ["g.",    "http://a/b/c/g."],
    [".g",    "http://a/b/c/.g"],
    ["g..",   "http://a/b/c/g.."],
    ["..g",   "http://a/b/c/..g"],

    // 3. Nonsensical path segments.
    ["./../g",     "http://a/b/g"],
    ["./g/.",      "http://a/b/c/g/"],
    ["g/./h",      "http://a/b/c/g/h"],
    ["g/../h",     "http://a/b/c/h"],
    ["g;x=1/./y",  "http://a/b/c/g;x=1/y"],
    ["g;x=1/../y", "http://a/b/c/y"],

    // 4. Paths in the query string should be ignored.
    ["g?y/./x",  "http://a/b/c/g?y/./x"],
    ["g?y/../x", "http://a/b/c/g?y/../x"],
    ["g#s/./x",  "http://a/b/c/g#s/./x"],
    ["g#s/../x", "http://a/b/c/g#s/../x"],

    // 5. Backwards compatibility
    ["http:g", "http:g"]
  ];
  for (var i=0; i < resolve_tests.length; i++) {
    var t = resolve_tests[i];
    var rel = new URI(t[0]);
    var abs = rel.resolve(base);
    is(t[1], abs.toString(), "Resolve '"+t[0]+"' to '"+t[1]+"'");
  };
</script></pre>
</body>
</html>
